package removeitem;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;

import java.util.HashMap;
import java.util.Set;

public class main extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
        getLogger().info("插件开启");
    }

    @Override
    public void onDisable() {
        getLogger().info("插件关闭");
    }

    // 检测玩家背包是否有足够物品
    // 扣除物品数量
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("removeitem")) {
            Player p = (Player) sender;
            sender.sendMessage(p.getDisplayName() + "你发送了removeitem");//发送信息
            PlayerInventory pi = p.getInventory();
            int sum = 0;
            HashMap hm = pi.all(Material.STONE);
            Set<Integer> set = hm.keySet();// 包含所有含有石头的格子
            for (int i : set){
                ItemStack is = pi.getItem(i);
                sum = sum + is.getAmount(); // 所有石头的总数
            }
            p.sendMessage("你拥有的石头数量" + String.valueOf(sum));
            return true;
        }
        return false;
    }

}